<?

function xlsx_filter_chr($s, $conv = false) {
	if($conv) {
		$s = iconv("gbk", "utf-8//ignore", $s);
	}
	if(strlen($s) > 30000) $s = substr($s, 0, 30000);
	$s2 = '';
	$len = strlen($s);
	for($i = 0; $i < $len; $i++) {
		$n = ord($s[$i]);
		if($n == 9 || $n == 10 || $n == 13 || ($n >= 32 && $n <= 126)) {
			$s2 .= $s[$i];
		} else if($n >= 0xE0 && $n <= 0xEF) {
			if($i+2 < $len) {
				$t1 = ord($s[$i+1]);
				$t2 = ord($s[$i+2]);
				if($t1 >= 128 && $t1 <= 191 && $t2 >= 128 && $t2 <= 191) {
					$s2 .= $s[$i].$s[$i+1].$s[$i+2];
					$i += 2;
				}
			}
		}
	}
	return htmlspecialchars($s2);
}
//function getXlsx($titles, $widths, $list, $fn) {
function getXlsxByList($titles, $widths, $list, $fn, $conv = false) {
	$sheets = array(array(
		'titles' => $titles,
		'widths' => $widths,
		'list' => $list,
		'sheet_name' => 'Sheet1',
	));
	return getXlsx($sheets, $fn, $conv);
}
function getXlsxBySQL($titles, $widths, $sql, $fn, $conv = false) {
	$sheets = array(array(
		'titles' => $titles,
		'widths' => $widths,
		'sql' => $sql,
		'sheet_name' => 'Sheet1',
	));
	return getXlsx($sheets, $fn, $conv);
}
function getXlsx($sheets, $fn, $conv = false) {
	$xlschars = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
	'AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ',
		'BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW','BX','BY','BZ',
		'CA','CB','CC','CD','CE','CF','CG','CH','CI','CJ','CK','CL','CM','CN','CO','CP','CQ','CR','CS','CT','CU','CV','CW','CX','CY','CZ',
		'DA','DB','DC','DD','DE','DF','DG','DH','DI','DJ','DK','DL','DM','DN','DO','DP','DQ','DR','DS','DT','DU','DV','DW','DX','DY','DZ'
	);
	$xmlstr_1 = '<?xml version="1.0" encoding="utf-8"?>'."\n".'<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac"><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection sqref="A1:A1"/></sheetView></sheetViews><sheetFormatPr defaultRowHeight="13.5" x14ac:dyDescent="0.15"/><cols>';

	$xmlstr_2 = '<phoneticPr fontId="1" type="noConversion"/><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/><pageSetup paperSize="9" orientation="portrait" r:id="rId1"/></worksheet>';

	$xmlstr_3 = '<?xml version="1.0" encoding="utf-8"?>'."\n".'<sst ####################uniqueCount#################### xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';

	$xmlstr_5 = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'."\n".'<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"><fileVersion appName="xl" lastEdited="6" lowestEdited="6" rupBuild="14420"/><workbookPr defaultThemeVersion="153222"/><mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"><mc:Choice Requires="x15"><x15ac:absPath url="C:\" xmlns:x15ac="http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac"/></mc:Choice></mc:AlternateContent><bookViews><workbookView xWindow="0" yWindow="0" windowWidth="28800" windowHeight="12450"/></bookViews><sheets>';

	$xmlstr_6 = '</sheets><calcPr calcId="152511"/><extLst><ext uri="{140A7094-0E35-4892-8432-C4D2E57EDEB5}" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"><x15:workbookPr chartTrackingRefBase="1"/></ext></extLst></workbook>';

	$xmlstr_7 = '<?xml version="1.0" encoding="utf-8"?>'."\n".'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>';

	$sourceZip = "UEsDBAoAAAAAANWJUU0AAAAAAAAAAAAAAAAJAAAAZG9jUHJvcHMvUEsDBBQAAAAIAAAAIQCFVevYjAEAABADAAAQAAAAZG9jUHJvcHMvYXBwLnhtbJ1SQW7bMBC8F8gfBN5jSklbFAbFoHBS5NCiBuzkvqVWFhGKJMiNYPctvfRQoD/oqb9JgT6jlAwrcpJTb7Ozg9FoluJi25qswxC1syUrZjnL0CpXabsp2c36w+k7lkUCW4FxFku2w8gu5MkrsQzOYyCNMUsWNpasIfJzzqNqsIU4S2ubNrULLVAaw4a7utYKL526b9ESP8vztxy3hLbC6tSPhmzvOO/of00rp/p88Xa988lPivfeG62A0l/KT1oFF11N2dVWoRF8uhTJaIXqPmjayVzw6ShWCgwukrGswUQU/JEQ1wh9aUvQIUrR0bxDRS5kUX9NtZ2x7AtE7OOUrIOgwRLby/bDgI2PFOSfXz8efn/7+/2n4CM3wKl0ivVrWQyCBI6FfMyR8HHCtSaD8XO9hEAvBC6mgYcMbBJx1SBS8Szf4UtPvBeu9WBTf3xEH7W9izd+7S6B8NDmMSlWDQSs0gHGtkdCXKdcwfT6RQN2g9VB83zR3/52/8Bl8WaWn+f5cPIDJ/jjU5b/AFBLAwQUAAAACAAAACEATtETS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AQAAAA7g4AAHhsL3RoZW1lL1BLAQIUABQAAAAIAAAAIQB3i32W9gUAAI8aAAATAAAAAAAAAAEAgAAAABUPAAB4bC90aGVtZS90aGVtZTEueG1sUEsBAhQACgAAAAAA8IlRTQAAAAAAAAAAAAAAAA4AAAAAAAAAAAAQAAAAPBUAAHhsL3dvcmtzaGVldHMvUEsBAhQACgAAAAAA1YlRTQAAAAAAAAAAAAAAABQAAAAAAAAAAAAQAAAAaBUAAHhsL3dvcmtzaGVldHMvX3JlbHMvUEsBAhQAFAAAAAgAAAAhADttMku7AAAAQgEAACMAAAAAAAAAAQCAAAAAmhUAAHhsL3dvcmtzaGVldHMvX3JlbHMvc2hlZXQxLnhtbC5yZWxzUEsBAhQACgAAAAAA1YlRTQAAAAAAAAAAAAAAAAkAAAAAAAAAAAAQAAAAlhYAAHhsL19yZWxzL1BLAQIUABQAAAAIAAAAIQBBN4LPXQEAAAQFAAATAAAAAAAAAAEAgAAAAL0WAABbQ29udGVudF9UeXBlc10ueG1sUEsBAhQACgAAAAAA1YlRTQAAAAAAAAAAAAAAAAYAAAAAAAAAAAAQAAAASxgAAF9yZWxzL1BLAQIUABQAAAAIAAAAIQC1VTAj6wAAAEwCAAALAAAAAAAAAAEAgAAAAG8YAABfcmVscy8ucmVsc1BLBQYAAAAAEAAQAAYEAACDGQAAAAA=";

	if(strtolower(substr($fn, -5)) != '.xlsx') {
		return false;
	}

	if(substr($fn, 0, 1) != '/' && !preg_match("/^[A-Za-z]\:/", $fn)) {
		$fn = getcwd()."/".$fn;
	}
	if(file_exists($fn)) {
		@unlink($fn);
		if(file_exists($fn)) return false;
	}
	$root = dirname($fn);

	$dir = opendir($root);
	while($t_fn = readdir($dir)) {
		if($t_fn == '.' || $t_fn == '..') continue;
		$tmpfn = $root."/".$t_fn;
		if(stristr($t_fn, '.xlsxtmp')) {
			if(time() - filemtime($tmpfn) > 600) @unlink($tmpfn);
		}
	}
	closedir($dir);

	file_put_contents($fn, base64_decode($sourceZip));
	$zip = new ZipArchive;
	$r = $zip->open($fn);
	if(!$r) {
		@unlink($fn);
		return false;
	}

	$wordInfo = array();

	$workbook = '';
	$rels = '';
	foreach($sheets as $n => $sitem) {
		$n1 = $n + 1;
		$sheet_name = $sitem['sheet_name'];
		if(!$sheet_name) $sheet_name = 'Sheet'.$n1;
		$workbook .= '<sheet name="'.xlsx_filter_chr($sheet_name, $conv).'" sheetId="'.$n1.'" r:id="rIdx'.$n1.'"/>';
		$rels .= '<Relationship Id="rIdx'.$n1.'" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet'.$n1.'.xml"/>';
	}
	$workbook = $xmlstr_5.$workbook.$xmlstr_6;
	$rels = $xmlstr_7.$rels.'</Relationships>';

	$zip->addFromString('xl/workbook.xml', $workbook);
	$zip->addFromString('xl/_rels/workbook.xml.rels', $rels);


	$strN = 1;
	$xmlstr2 = $xmlstr_3.'><si><t></t><phoneticPr fontId="1" type="noConversion"/></si>';
	$fn2 = $root."/".md5(microtime()."xml2").".xlsxtmp";
	$fileList = array($fn2);
	foreach($sheets as $sn => $sitem) {
		$titles = $sitem['titles'];
		$widths = $sitem['widths'];
		$list = $sitem['list'];
		$sql = $sitem['sql'];
		$all_text = $sitem['all_text'];
		$mergeCells = $sitem['mergeCells']; //合并表格
		$issql = false;
		if($sql) $issql = true;
		
		$fn1 = $root."/".md5(microtime().$fn1).".xlsxtmp";
		$fileList[] = $fn1;
		if($issql) {
			$rs = mysql_query($sql);
			if(!$rs) {
				return false;
			}
			if(!$titles) {
				$titles = array();
				while($row = mysql_fetch_field($rs)) {
					$titles[] = $row->name;
				}
			}
		}
		
		$titlesAll = $titles;
		if(!is_array($titlesAll[0])) {
			$titlesAll = array($titlesAll);
		}
		$titles = $titlesAll[0];

		$colnum = count($titles);

		$colstr = '';
		foreach($titles as $n => $title) {
			$width = 15;
			if($widths && $widths[$n]) $width = $widths[$n];

			$text_s = '';
			if($all_text) {
				$text_s = ' style="2"';
			}
			$colstr .= '<col min="'.($n+1).'" max="'.($n+1).'" width="'.$width.'"'.$text_s.' customWidth="1"/> ';
		}
		$xmlstr = $xmlstr_1.$colstr.'</cols><sheetData>';
		$title_count = count($titlesAll);
		foreach($titlesAll as $n => $titles) {
			$xmlstr .= '<row r="'.($n+1).'" spans="1:2" x14ac:dyDescent="0.15">';
			foreach($titles as $n2 => $title) {
				if($wordInfo[$title]) {
					$idx = $wordInfo[$title];
				} else {
					$idx = $strN;
					$wordInfo[$title] = $idx;
					$strN++;
					$xmlstr2 .= '<si><t>'.xlsx_filter_chr($title, $conv).'</t><phoneticPr fontId="1" type="noConversion"/></si>';
				}
				$xmlstr .= '<c r="'.$xlschars[$n2].($n+1).'" s="'.($all_text?"5":"1").'" t="s"><v>'.$idx.'</v></c>';
			}
			$xmlstr .= '</row>';

		}
		$n1 = -1;
		while(1) {
			$n1++;
			if($issql) {
				$item = mysql_fetch_row($rs);
				if(!$item) break;
			} else {
				if($n1 >= count($list)) break;
				$item = $list[$n1];
			}

			$xmlstr .= '<row r="'.($n1+1+$title_count).'" spans="1:'.$colnum.'" x14ac:dyDescent="0.15">';
			foreach($item as $n2 => $value) {
				$value = $value.'';
				if($value == '') {
					$xmlstr .= '<c r="'.$xlschars[$n2].($n1+1+$title_count).'" t="s"><v>0</v></c>';
					continue;
				}
				
				if(substr($value, 0, 3) == '#s#') {
					$value = trim(substr($value, 3));
					if($value == '') {
						$xmlstr .= '<c r="'.$xlschars[$n2].($n1+1+$title_count).'" t="s"><v>0</v></c>';
						continue;
					}
				} else {
					if(is_numeric($value)) {
						if(strstr($value, ".") || $value == '0') {
							if(substr($value, 0, 1) == '.') $value = "0".$value;
							$xmlstr .= '<c r="'.$xlschars[$n2].($n1+1+$title_count).'"><v>'.$value.'</v></c>';
							continue;
						} else {
							if(substr($value, 0, 1) != '0' && strlen($value) <= 10) {
								$xmlstr .= '<c r="'.$xlschars[$n2].($n1+1+$title_count).'"><v>'.$value.'</v></c>';
								continue;
							} 
							
						}
					} else {
						$value1 = str_replace('%', '', $value);
						if(is_numeric($value1)) {
							$value1 = $value1/100;
							$xmlstr .= '<c r="'.$xlschars[$n2].($n1+1+$title_count).'" s="4"><v>'.$value1.'</v></c>';
							continue;
						}
					}
				}
				if($wordInfo[$value]) {
					$idx = $wordInfo[$value];
				} else {
					$idx = $strN;
					$wordInfo[$value] = $idx;
					$strN++;
					$xmlstr2 .= '<si><t>'.xlsx_filter_chr($value, $conv).'</t><phoneticPr fontId="1" type="noConversion"/></si>'."\n";
				}

				$xmlstr .= '<c r="'.$xlschars[$n2].($n1+1+$title_count).'" t="s" s="2"><v>'.$idx.'</v></c>';
			}
			$xmlstr .= '</row>';
			if(strlen($xmlstr) > 50000) {
				file_put_contents($fn1, $xmlstr, FILE_APPEND);
				$xmlstr = '';
			}
			if(strlen($xmlstr2) > 50000) {
				file_put_contents($fn2, $xmlstr2, FILE_APPEND);
				$xmlstr2 = '';
			}
		}
		$xmlstr .= '</sheetData>';
		if($mergeCells) {
			$xmlstr .= '<mergeCells count="'.count($mergeCells).'">';
			foreach($mergeCells as $mitem) {
				$xmlstr .= '<mergeCell ref="'.$mitem.'"/>';
			}
			$xmlstr .= '</mergeCells>';
		}
		$xmlstr .= $xmlstr_2;
		file_put_contents($fn1, $xmlstr, FILE_APPEND);
		$zip->addFile($fn1, 'xl/worksheets/sheet'.($sn+1).'.xml');
	}
	$xmlstr2 .= '</sst>';
	file_put_contents($fn2, $xmlstr2, FILE_APPEND);
	
	$s = 'uniqueCount="'.$strN.'" count="'.$strN.'"';
	$s = str_pad($s, 51, ' ', STR_PAD_BOTH);
	$fp = fopen($fn2, "r+b");
	fseek($fp, 44, SEEK_SET);
	fwrite($fp, $s);
	fclose($fp);

	$zip->addFile($fn2, 'xl/sharedStrings.xml');
	
	$zip->close();
	foreach($fileList as $fn) @unlink($fn);

	return true;
}
